//
//  MCBankcardManageTableViewCell.m
//  TLYL
//
//  Created by MC on 2017/7/11.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCBankcardManageTableViewCell.h"
@interface MCBankcardManageTableViewCell ()
/*
 * 打底
 */
@property (nonatomic,strong)UIImageView * backView;

/*
 * 图标
 */
@property (nonatomic,strong)UIImageView * logoImgV;
/*
 * 卡的名称
 */
@property (nonatomic,strong)UILabel * cardNameLab;
/*
 * 卡号
 */
@property (nonatomic,strong)UILabel * cardNumberLab;


@end

@implementation MCBankcardManageTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

- (void)initView{
    
    self.backgroundColor=[UIColor clearColor];
    
    
    _backView=[[UIImageView alloc]init];
    [self addSubview:_backView];
//    _backView.backgroundColor=RGB(240, 110, 125);
    _backView.frame=CGRectMake(0, 0, G_SCREENWIDTH, 115+20);
//    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_backView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//    maskLayer.frame = _backView.bounds;
//    maskLayer.path = maskPath.CGPath;
//    _backView.layer.mask = maskLayer;
//    _backView.clipsToBounds=YES;
    
//    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.left.right.equalTo(self);
//        
//    }];
    
    /*
     * logo
     */
    _logoImgV=[[UIImageView alloc]init];
    [_backView addSubview:_logoImgV];
    _logoImgV.frame=CGRectMake(10, 25, 30, 30);
//    _logoImgV.image=[UIImage imageNamed:@"Bank-card-white"];


    /*
     * 卡的名称
     */
    _cardNameLab =[[UILabel alloc]initWithFrame:CGRectZero];
    _cardNameLab.textColor=[UIColor whiteColor];
    _cardNameLab.font=[UIFont boldSystemFontOfSize:14];
    _cardNameLab.text =@"加载中...";
    _cardNameLab.textAlignment=NSTextAlignmentLeft;
    [_backView  addSubview:_cardNameLab];
    
    /*
     * 卡号
     */
    _cardNumberLab =[[UILabel alloc]initWithFrame:CGRectZero];
    _cardNumberLab.textColor=[UIColor whiteColor];
    _cardNumberLab.font=[UIFont systemFontOfSize:18];
    _cardNumberLab.text =@"加载中...";
    _cardNumberLab.textAlignment=NSTextAlignmentLeft;
    [_backView  addSubview:_cardNumberLab];
    

    
    [self relayOutConstraints];
    
    
    
}



-(void)relayOutConstraints{
    
    
    
    [_cardNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_logoImgV.mas_top);
        make.height.mas_equalTo(18);
        make.width.mas_equalTo(G_SCREENWIDTH-90);
        make.left.equalTo(_logoImgV.mas_right).offset(10);
    }];
    
    
    [_cardNumberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_cardNameLab.mas_bottom);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(G_SCREENWIDTH-90);
        make.left.equalTo(_logoImgV.mas_right).offset(10);
    }];
    
    


    
}

-(void)setDataSource:(MCBankModel *)dataSource{
    
    _dataSource=dataSource;
    _cardNumberLab.text=dataSource.bankNumer;

    //默认银行卡
    if ([dataSource.Isdefault intValue]==1) {
        
        _cardNameLab.text=[NSString stringWithFormat:@"%@ (默认此卡)",dataSource.bankName];

    }else{

       _cardNameLab.text =dataSource.bankName;
    }
    
    _logoImgV.image=[UIImage imageNamed:dataSource.BankCode];

}

-(void)setBack:(BOOL)isSignal{
    if (isSignal) {
        _backView.image=[UIImage imageNamed:@"BankBack1"];
    }else{
        _backView.image=[UIImage imageNamed:@"BankBack2"];
    }
}

+(CGFloat)computeHeight:(id)info{
    
    return 115;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
